﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure;

namespace Traceability.App.Applications.DeepProcess
{
    public class DeepProcessQueryCommandHandler : IRequestHandler<DeepProcessQueryCommand, APIResult<T_DeepProcess>>
    {
        private readonly IBaseRepository<T_DeepProcess> deepRepository;

        public DeepProcessQueryCommandHandler(IBaseRepository<T_DeepProcess> deepRepository)
        {
            this.deepRepository = deepRepository;
        }

        public Task<APIResult<T_DeepProcess>> Handle(DeepProcessQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<T_DeepProcess> result = new APIResult<T_DeepProcess>();
            result.Code = APIEnum.ok;
            result.Message = "获取成功";
            result.Data = deepRepository.GetAll().AsNoTracking().FirstOrDefault(x => x.Batch == request.Batch);
            return Task.FromResult(result);
        }
    }
}
